<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改设备')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-machine-edit" th:object="${machine}">
            <input name="id" th:field="*{id}" type="hidden">
            <input id="projectName" name="projectName" th:field="*{projectName}" type="hidden">
            <input id="projectNo" name="projectNo" th:field="*{projectNo}" type="hidden">
            <input id="projectType" name="projectType" th:field="*{projectType}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">项目名称：</label>
                <div class="col-sm-8">
                    <select id="projectId" name="projectId" class="form-control m-b" th:with="projectList=${projectList}">
                        <option th:each="project : ${projectList}" th:text="${project.projectName}" th:value="${project.id}"
                                th:field="*{projectId}" th:attr="data-project-id=${project.id}, data-project-name=${project.projectName}, data-project-no=${project.projectNo}, data-project-type=${project.projectType}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">设备类型：</label>
                <div class="col-sm-8">
                    <select name="machineType" class="form-control m-b" th:with="type=${@dict.getType('lh_machine_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{machineType}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">设备型号：</label>
                <div class="col-sm-8">
                    <input name="machineNo" th:field="*{machineNo}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">设备名称：</label>
                <div class="col-sm-8">
                    <input name="machineName" th:field="*{machineName}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">初始软件版本：</label>
                <div class="col-sm-8">
                    <select name="initialSoftwareVersion" class="select2-multiple form-control m-b" data-none-selected-text="请选择" th:with="type=${@dict.getType('lh_software_version')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:attr="selected=${machine.initialSoftwareVersion != null && machine.initialSoftwareVersion.contains(dict.dictValue)?true:false}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">硬件版本：</label>
                <div class="col-sm-8">
                    <select name="hardwareVersion" class="select2-multiple form-control m-b" data-none-selected-text="请选择" th:with="type=${@dict.getType('lh_hardware_version')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:attr="selected=${machine.hardwareVersion != null && machine.hardwareVersion.contains(dict.dictValue)?true:false}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">软件/设备SN：</label>
                <div class="col-sm-8">
                    <input name="sn" th:field="*{sn}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">软件/设备状态：</label>
                <div class="col-sm-8">
                    <select name="status" class="form-control m-b" th:with="type=${@dict.getType('lh_machine_open')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{status}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否允许更新：</label>
                <div class="col-sm-8">
                    <select name="isAcceptUpdate" class="form-control m-b" th:with="type=${@dict.getType('lh_machine_accept')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{isAcceptUpdate}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">出厂时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="releaseDate" th:value="${#dates.format(machine.releaseDate, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">设备所在区域：</label>
                <div class="col-sm-8">
                    <select name="releaseArea" class="form-control m-b" th:with="type=${@dict.getType('lh_machine_area')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{releaseArea}"></option>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "lh/machine";
        $("#form-machine-edit").validate({
            focusCleanup: true
        });

        $('#projectId').on('change', function(){
           var thisValue = $(this).val();
           $('#projectId > option').each(function(index, element) {
               if(thisValue == $(element).attr('value')) {
                   $('#projectName').val($(element).attr('data-project-name'));
                   $('#projectNo').val($(element).attr('data-project-no'));
                   $('#projectType').val($(element).attr('data-project-type'));
               }
           });
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-machine-edit').serialize());
            }
        }

        $("input[name='releaseDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>